Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contentful/rich-text-html-renderer

Package Overview
Dependencies
Maintainers
0
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contentful/rich-text-html-renderer

HTML renderer for the Contentful rich text field type.

  • 16.6.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
149K
decreased by-0.38%
Maintainers
0
Weekly downloads
 
Created

What is @contentful/rich-text-html-renderer?

@contentful/rich-text-html-renderer is an npm package that allows you to convert Contentful's rich text document format into HTML. This is particularly useful for rendering rich text content stored in Contentful CMS into web pages.

What are @contentful/rich-text-html-renderer's main functionalities?

Rendering Rich Text to HTML

This feature allows you to convert a Contentful rich text document into an HTML string. The code sample demonstrates how to use the `documentToHtmlString` function to achieve this.

const { documentToHtmlString } = require('@contentful/rich-text-html-renderer');
const richTextDocument = {
  nodeType: 'document',
  content: [
    {
      nodeType: 'paragraph',
      content: [
        {
          nodeType: 'text',
          value: 'Hello, world!',
          marks: [],
          data: {}
        }
      ],
      data: {}
    }
  ],
  data: {}
};
const htmlString = documentToHtmlString(richTextDocument);
console.log(htmlString); // Outputs: <p>Hello, world!</p>

Customizing HTML Output

This feature allows you to customize the HTML output by providing options to the `documentToHtmlString` function. The code sample shows how to add a custom class to paragraph elements.

const { documentToHtmlString } = require('@contentful/rich-text-html-renderer');
const richTextDocument = {
  nodeType: 'document',
  content: [
    {
      nodeType: 'paragraph',
      content: [
        {
          nodeType: 'text',
          value: 'Hello, world!',
          marks: [],
          data: {}
        }
      ],
      data: {}
    }
  ],
  data: {}
};
const options = {
  renderNode: {
    'paragraph': (node, next) => `<p class="custom-class">${next(node.content)}</p>`
  }
};
const htmlString = documentToHtmlString(richTextDocument, options);
console.log(htmlString); // Outputs: <p class="custom-class">Hello, world!</p>

Other packages similar to @contentful/rich-text-html-renderer

FAQs

Package last updated on 09 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc